/**
 * Created by lins on 2018-7-11.
 */
angular.module('MetronicApp').controller('LabelSystemListController',
    ['$rootScope', '$scope', '$state', '$stateParams', '$uibModal', 'toastr', 'EnumService', 'LabelSysService',
        function ($rootScope, $scope, $state, $stateParams, $uibModal, toastr, EnumService, LabelSysService) {
            $scope.$on('$viewContentLoaded', function () {
                App.initAjax();
                $rootScope.settings.layout.pageBodySolid = true;
                $rootScope.settings.layout.pageSidebarClosed = false;
            });



            $scope.condition = {};
            $scope.analysis = EnumService.get("analysisIndex");

            $scope.tabItemList = [
                {
                    "name": "标签体系",
                    "router": "labelSystemList",
                    "selected": true
                },
                {
                    "name": "企业信息",
                    "router": "informationList",
                    "selected": false
                },
                {
                    "name": "挖掘算法",
                    "router": "algorithmList",
                    "selected": false
                },
                {
                    "name": "企业画像",
                    "router": "businessPortraitList",
                    "selected": false
                },
                {
                    "name": "标签检索",
                    "router": "labelRetrievalList",
                    "selected": false
                }
            ]

            //获取ng-table表头
            $scope.columns = LabelSysService.getSchema();
            $scope.pageable = LabelSysService.getPageable();

            //监听值得变化
            $scope.$watch('pageable.size', function (newVal, oldVal) {
                if (newVal === oldVal) return;
                LabelSysService.setSize(newVal);
                $scope.list();
            });
            $scope.$watch('pageable.number', function (newVal, oldVal) {
                if (newVal === oldVal) return;
                LabelSysService.setStoredPage(newVal);
                $scope.list();
            });

            $scope.list = function () {
                LabelSysService.putSearchParams({
                    search: $scope.condition.search
                });
                LabelSysService.list(function (res) {
                    if ('success' === res.status) {
                        $scope.socialRows = res.data;
                        $scope.pageable = res.pageable;
                    } else {
                        for (var i = 0; i < res.errors.length; i++) {
                            toastr.error(res.errors[i].errmsg, "数据获取失败");
                        }
                    }
                });
            };

            //左边标签体系tab点击背景变色
            $("#myTab li").click(function (e) {
                $(this).addClass('selected');
                $(this).siblings('li').removeClass('selected');
                e.preventDefault();
                //获取索引下标 也从0开始
                // var textword = $(this).text();  //文本内容
                // alert("下标索引值为：" + item );

            });

            //给左边标签体系tab增加点击事件，切换li标签内容
            $scope.changeTab = function (index) {
                switch (index) {
                    //社会影响
                    case 0:
                        LabelSysService.putSearchParams({
                            search: $scope.condition.search
                        });
                        LabelSysService.getUrl(index).$promise.then(function (res) {
                            if ('success' == res.status) {
                                $scope.socialRows = res.data;
                                $scope.pageable = res.pageable;
                            } else {
                                for (var res in result.errors) {
                                    toastr.error("数据获取失败！", res.errors[index].errmsg);
                                    return;
                                }
                            }
                        });
                        break;
                        //排污情况
                    case 1:
                        LabelSysService.putSearchParams({
                            search: $scope.condition.search
                        });
                        LabelSysService.getUrl(index).$promise.then(function (res) {
                            if ('success' == res.status) {
                                $scope.pollutionRows = res.data;
                            } else {
                                for (var res in result.errors) {
                                    toastr.error("数据获取失败！", res.errors[index].errmsg);
                                    return;
                                }
                            }
                        });
                        break;
                        //经营情况
                    case 2:
                        LabelSysService.putSearchParams({
                            search: $scope.condition.search
                        });
                        LabelSysService.getUrl(index).$promise.then(function (res) {
                            if ('success' == res.status) {
                                $scope.businessRows = res.data;
                            } else {
                                for (var res in result.errors) {
                                    toastr.error("数据获取失败！", res.errors[index].errmsg);
                                    return;
                                }
                            }
                        });
                        break;
                        //数据事实-基本属性
                    case 3:
                        LabelSysService.putSearchParams({
                            search: $scope.condition.search
                        });
                        LabelSysService.getUrl(index).$promise.then(function (res) {
                            if ('success' == res.status) {
                                $scope.basicRows = res.data;
                            } else {
                                for (var res in result.errors) {
                                    toastr.error("数据获取失败！", res.errors[index].errmsg);
                                    return;
                                }
                            }
                        });

                        break;
                    //数据事实-统计属性
                    case 4:
                        LabelSysService.putSearchParams({
                            search: $scope.condition.search
                        });
                        LabelSysService.getUrl(index).$promise.then(function (res) {
                            if ('success' == res.status) {
                                $scope.countRows = res.data;
                                console.log($scope.countRows)
                            } else {
                                for (var res in result.errors) {
                                    toastr.error("数据获取失败！", res.errors[index].errmsg);
                                    return;
                                }
                            }
                        });
                        break;
                    //排污效益
                    case 5:
                        LabelSysService.putSearchParams({
                            search: $scope.condition.search
                        });
                        LabelSysService.getUrl(index).$promise.then(function (res) {
                            if ('success' == res.status) {
                                $scope.benefitRows = res.data;
                            } else {
                                for (var res in result.errors) {
                                    toastr.error("数据获取失败！", res.errors[index].errmsg);
                                    return;
                                }
                            }
                        });
                        break;
                    //排污影响
                    case 6:
                        LabelSysService.putSearchParams({
                            search: $scope.condition.search
                        });
                        LabelSysService.getUrl(index).$promise.then(function (res) {
                            if ('success' == res.status) {
                                $scope.influenceRows = res.data;
                            } else {
                                for (var res in result.errors) {
                                    toastr.error("数据获取失败！", res.errors[index].errmsg);
                                    return;
                                }
                            }
                        });
                        break;
                    //环境信用
                    case 7:
                        LabelSysService.putSearchParams({
                            search: $scope.condition.search
                        });
                        LabelSysService.getUrl(index).$promise.then(function (res) {
                            if ('success' == res.status) {
                                $scope.creditRows = res.data;
                            } else {
                                for (var res in result.errors) {
                                    toastr.error("数据获取失败！", res.errors[index].errmsg);
                                    return;
                                }
                            }
                        });
                        break;
                    //重污染天气减限产
                    case 8:
                        LabelSysService.putSearchParams({
                            search: $scope.condition.search
                        });
                        LabelSysService.getUrl(index).$promise.then(function (res) {
                            if ('success' == res.status) {
                                $scope.weatherRows = res.data;
                            } else {
                                for (var res in result.errors) {
                                    toastr.error("数据获取失败！", res.errors[index].errmsg);
                                    return;
                                }
                            }
                        });
                        break;
                }
                // tempThis.addClass('transform-left').removeClass('transform-right')
                // $(".tab-pane.in.active.mark-no-mean").removeClass('transform-left')
                // $(".tab-pane.in.active.mark-no-mean").addClass('transform-right')
                // tempThis = $(".tab-pane.in.active.mark-no-mean")
            };

            var gotoFirstPage = function () {
                LabelSysService.setStoredPage(0);
                $scope.list();
                LabelSysService.clearSearchParams();
            };
            gotoFirstPage();

            //查询
            $scope.search = function () {
                gotoFirstPage();
            };

           /* //编辑
            $scope.edit = function (row) {
                $state.go('labelSystemEdit', {id: row.id});
            };

            //详情
            $scope.view = function (row) {
                $state.go('labelSystemView', {id: row.id});
            };*/

        }
    ]
);